<template>
  <div>
    <inventoryDetail v-if="detailVisible" @changeDetailVisible="changeDetailVisible" :effPlanDetail="effPlanDetail">
    </inventoryDetail>
    <addInventoryPlan v-if="addVisible" @addPlan="addPlan" :editId="planId" :planType="planType">
    </addInventoryPlan>
    <div class="project zy-content" v-show="!detailVisible && !addVisible">
      <Tabs class="tabs-layout mb16" @on-click="tabsClick" v-model="status" :animated="false">
        <TabPane :label="$t('maintenance.ValidPlan')" name="1"></TabPane>
        <TabPane :label="$t('maintenance.InvalidPlan')" name="0"></TabPane>
      </Tabs>
      <list ref="list" @addPlan="addPlan" @changeDetailVisible="changeDetailVisible"></list>
    </div>
  </div>
</template>

<script>
import list from './modal/list.vue'
import addInventoryPlan from './modal/addInventoryPlan.vue'
import inventoryDetail from './modal/inventoryDetail.vue'

export default {
  name: 'inventoryPlan',
  components: {
    list,
    addInventoryPlan,
    inventoryDetail
  },
  data() {
    return {
      status: '1',
      planId: '',
      planType: '',
      addVisible:false,
      detailVisible:false,
      effPlanDetail:{},
    }
  },
  methods: {
    tabsClick(name) {
      this.status = name
      this.$refs.list.searchList(name)
    },
    addPlan(flag, row, str) {
      this.addVisible = flag
      if (!flag) {
        this.$refs.list.searchList(this.status)
      } else {
        if(str==='new'){
          this.planType = this.$t('新建盘点计划')
        }else if(str==='edit'){
          this.planType = this.$t('编辑盘点计划')
        }else if(str==='copy'){
          this.planType = this.$t('复制盘点计划')
        }
      }
      if (row.id) {
        this.planId = row.id
      } else {
        this.planId = ''
      }
    },
    changeDetailVisible(flag, id) {
      this.detailVisible = flag
      if (!flag) {
        this.$refs.list.searchList(this.status)
      }
      if (id) {
        this.getPlanDetail(id)
      }
    },
    getPlanDetail(id) {
      this.axios({
        method: 'get',
        url: '/dms/dmsBackupPlan/queryById',
        params: { id }
      }).then(async res => {
        if (res.code === 200) {
          this.effPlanDetail = {
            ...res.data
          }
        } else {
          this.$Message.warning({ content: res.msg, duration: 6, closable: true })
        }
      })
    },
  }
}
</script>